package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CLoginByPwd
import com.onlyphoto.onlymall.mvp.model.MLoginByPwdImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.UserInfoBean


class PLoginByPwdImpl(mContext: Context, mView: CLoginByPwd.IVLoginByPwd) : BasePresenter<CLoginByPwd.IVLoginByPwd, MLoginByPwdImpl>(mContext, mView, MLoginByPwdImpl()), CLoginByPwd.IPLoginByPwd {
    override fun loginByPwd() {
        val bean = mView.getLoginEntity()
        mModel.loginByPwd(bean, object :BaseObserver<UserInfoBean>(mContext.get()){
            override fun onSuccess(data: UserInfoBean?, msg: String?) {
                mView.loginSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<UserInfoBean>?) {
                if (t?.error_code == 1) {
                    mView.showMsg(t.msg!!)
                } else {
                    mView.showMsg("登录失败，请稍后重试！")
                }
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
